package com.github.shiqiyue.app.modules.dbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.shiqiyue.app.modules.dbms.entity.UserSqlCollect;
import com.github.shiqiyue.app.modules.dbms.mapper.UserSqlCollectMapper;
import com.github.shiqiyue.app.modules.dbms.service.IUserSqlCollectService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户收藏的SQL 服务实现类
 * </p>
 *
 * @author wenyao.wu
 * @since 2019-08-06
 */
@Service
public class UserSqlCollectServiceImpl extends ServiceImpl<UserSqlCollectMapper, UserSqlCollect> implements IUserSqlCollectService {


    @Override
    public List<UserSqlCollect> listByUserId(Long userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(UserSqlCollect.USER_ID, userId);
        return this.list(queryWrapper);
    }

    @Override
    public List<UserSqlCollect> listByUserIdAndDatabaseId(Long userId, Long databaseId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(UserSqlCollect.USER_ID, userId);
        queryWrapper.eq(UserSqlCollect.DATABASE_ID, databaseId);
        return this.list(queryWrapper);
    }

    @Override
    public void deleteByUserIdAndId(Long userId, Long id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(UserSqlCollect.USER_ID, userId);
        queryWrapper.eq(UserSqlCollect.ID, id);
        this.remove(queryWrapper);
    }
}
